# Contributor: Oleg Titov <oleg.titov@gmail.com>
# Maintainer: Oleg Titov <oleg.titov@gmail.com>
pkgname=singularity
pkgver=3.5.3
pkgrel=0
pkgdesc="Application containers focused on reproducibility for scientific computing and HPC world."
url="https://www.sylabs.io/singularity/"
arch="all !mips !mips64" # fails to build on mips
license="BSD-3-Clause BSD-3-Clause-LBNL"
options="chmod-clean suid !check" # no test suite from upstream
depends="squashfs-tools"
makedepends="
	go
	linux-headers
	binutils-gold
	openssl-dev
	libuuid
	util-linux-dev
	libseccomp-dev
	cryptsetup
	"
subpackages="$pkgname-doc $pkgname-bash-completion:bashcomp:noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/hpcng/singularity/archive/v$pkgver.tar.gz
	pie.patch
	"
builddir="$srcdir/src/github.com/hpcng/$pkgname"

# secfixes:
#   3.5.2-r0:
#     - CVE-2019-19724

prepare() {
	export GOPATH="$srcdir"

	mkdir -p "$(dirname $builddir)"
	mv "$srcdir"/$pkgname-$pkgver "$builddir"/

	echo "$pkgver" > "$builddir"/VERSION
	default_prepare
}

build() {
	export GOPATH="$srcdir"
	export GOBIN="$GOPATH/bin"

	./mconfig \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/infodir \
		--localstatedir=/var

	make -C builddir
}

package() {
	make -C builddir DESTDIR="$pkgdir" install

	install -m644 -D -t "$pkgdir/usr/share/doc/$pkgname" README.md

	mkdir -p "$pkgdir"/usr/share/bash-completion/completions
	mv "$pkgdir"/etc/bash_completion.d/singularity \
		"$pkgdir"/usr/share/bash-completion/completions
}

sha512sums="658f17960730f80bb6d6a2cdfebd565cbe3c5f263d9b8d7a26e84a7a22d9b6970322acb97e851b616a3ef53b88019d54b4677f56f4c29e8e4e484e6e72e170c9  singularity-3.5.3.tar.gz
51fb468468e3e313e1ad60446d18bb790c4121854d2aeb34854eb8f3f128d5452ecc3df53d1d00b930ea388a71704e75a466f3e35decbb30d8fda2c5c905d960  pie.patch"
